package ac.github.os.internal.core.condition.impl.script

import ac.github.os.OriginSkill
import ac.github.os.internal.core.condition.Condition
import ac.github.os.internal.core.config.StringConfig
import ac.github.os.internal.core.config.get
import ac.github.os.internal.session.Session
import taboolib.common.platform.Awake
import taboolib.common.platform.function.info
import taboolib.common5.Coerce
import taboolib.common5.compileJS

@Awake
class JavaScriptCondition : Condition {
    override fun doScreen(session: Session, config: StringConfig): Boolean {
        val string = config.get<String>("val", single = true) ?: return false
        val eval = string.compileJS()?.eval()
        val boolean = Coerce.toBoolean(eval)
        OriginSkill.debug {
            info("debug js string $string eval result $eval as $boolean")
        }
        return boolean
    }

    override val namespace: String
        get() = "b"
}